package at.jku.ase.communication.parsers;

import at.jku.ase.communication.SessionObject;
import at.jku.ase.utils.XMLUtils;

import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;

/**
 * Created by IntelliJ IDEA.
 * User: stellit
 * Date: 12/19/11
 * Time: 11:19 AM
 * To change this template use File | Settings | File Templates.
 */
public class DataParser extends ComponentParser {

    public DataParser(final SessionObject session, final XMLResponse action) {
        super(session, action);
    }

    @Override
    protected Object processRequest(XMLStreamReader reader) throws XMLStreamException {
        if (reader.next() == XMLStreamConstants.CHARACTERS) {
            System.out.println("Parsing data object");
            String keyChars = reader.getText();
            byte[] data = XMLUtils.base64ToByteArray(keyChars);
            this.getSession().setData(data);
        }
        return null;
    }
}
